<template>
    <div>
        <el-date-picker
            size="mini"
            @change="changeHandel"
            v-model="date"
            type="datetime"
            style="width:128px;"
            placeholder="选择时间"
            >
        </el-date-picker>
    </div>
</template>



<script>
export default{
    props:[
       "defaultValue"
    ],
    data(){
        return{
            date:"",
        }
    },
    mounted() {
        this.date = this.defaultValue
    },
    methods:{
        changeHandel(v){
            if(v){
                var date = new Date(v)
                var month,day,hours,minutes,seconds
                    //月
                    if(date.getMonth() < 10){
                        month = "0"+ (date.getMonth()+1)
                    }else{
                        month = (date.getMonth() + 1)
                    }
                    //日
                    if(date.getDate() < 10){
                        day = "0"+ date.getDate()
                    }else{
                        day = date.getDate()
                    }
                    //时
                    if(date.getHours() < 10){
                        hours = "0"+ date.getHours()
                    }else{
                        hours = date.getHours()
                    }
                    //分
                    if(date.getMinutes() < 10){
                        minutes = "0"+ date.getMinutes()
                    }else{
                        minutes = date.getHours()
                    }
                    //秒
                    if(date.getSeconds() < 10){
                        seconds = "0"+ date.getSeconds()
                    }else{
                        seconds = date.getSeconds()
                    }
                var date_value=date.getFullYear() + '-' + month + '-' + day + ' ' + hours  + ':' + minutes + ':' + seconds
                this.$emit("change", "caozuoDateSelect", date_value)
            }else{
                this.$emit("change", "caozuoDateSelect", v)
            }
            
        },
        reset(){
            this.date = "";
            this.changeHandel(this.date)
		},

    }
}
</script>